package com.sq.partner.manager.webservice;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.log4j.Logger;

import com.sq.partner.manager.common.Config;
import com.sq.partner.manager.sso.webservice.ServiceException_Exception;
import com.sq.partner.manager.util.LogUtil;
import com.sq.partner.manager.webservice.payment.PayRequestPortType;

public class PaymentClient {
	private static Logger logger = LogUtil.getLog(PaymentClient.class);
	private static PayRequestPortType payRequestPortType = null;
	static {
		try {
			String url = Config.getProp("nlife.webservice.payUrl");
			logger.info("支付平台webservice请求地址:" + url);
			// 创建WebService客户端代理工厂
			JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
			// 注册WebService接口
			factory.setServiceClass(PayRequestPortType.class);
			// 设置WebService地址
			factory.setAddress(url);
			payRequestPortType = (PayRequestPortType) factory.create();
		} catch (Exception e) {
			logger.error("支付平台webservice URL 初使化失败", e);
		}
		logger.info("支付平台webservice URL 初使化成功");
	}

	/**
	 * CIC报文发送
	 * @param requestXml
	 * @return
	 * @throws ServiceException_Exception
	 */
	public static String getRequest(String requestXml)
			throws ServiceException_Exception {
		return payRequestPortType.getRequest(requestXml);
	}

	public static void main(String[] args) throws Exception {
		String requestXml = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n"
				+ "<PAYREQ>\n" + "  <HEAD>\n"
				+ "    <USER_NAME>ECUser</USER_NAME>\n"
				+ "    <USER_PSW>EC100</USER_PSW>\n" + "  </HEAD>\n"
				+ "  <BASE>\n" + "    <TRANSTYPE>P003</TRANSTYPE>\n"
				+ "      <SERIALNUMBER>ZC20181000150212PAY0001</SERIALNUMBER>\n" + "  </BASE>\n"
                + "  <MAIN>\n" + "    <REQUESTCODE>0001</REQUESTCODE>\n"
                + "             <PAYID>ZC20181000150212</PAYID>\n" 
                + "  <SIGN>bcafbc49cb9044c292d550beb93b1d71</SIGN>\n" + "  </MAIN>\n"
				+ "</PAYREQ>";
		System.out.println(getRequest(requestXml));

	}
}
